package com.zs.test;

import com.zs.pojo.Employee;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

/**
 * @author ZhouShuang
 * @version 17
 * @Title
 * @date 2025/6/11 下午4:28
 */
public class UseEmpClass {
    public static void main(String[] args) throws Exception {
        Class<?> clzz = Employee.class;
        Employee employee = (Employee) clzz.
                getConstructor(String.class, String.class, String.class, double.class).
                newInstance("JD1001", "John Doe", "Manager", 50000.0);
        Method showInfo = clzz.getMethod("showInfo");
        showInfo.invoke(employee);
        System.out.println("----------------------------------------------");
        Field field = clzz.getDeclaredField("empNo");
        field.setAccessible(true);
        field.set(employee, "JD1002");
        showInfo.invoke(employee);
        System.out.println("----------------------------------------------");
        Method setEmpNo = clzz.getMethod("setEmpNo", String.class);
        setEmpNo.invoke(employee, "JD1003");
        showInfo.invoke(employee);
    }
}
